package com.techsoul.module.pms.controller;

import com.techsoul.common.core.exception.ExcelException;
import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.core.pojo.vo.UserVo;
import com.techsoul.common.core.util.ServletUtils;
import com.techsoul.common.core.util.collection.ListUtils;
import com.techsoul.common.core.util.poi.ExcelImport;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.common.security.service.TokenService;
import com.techsoul.module.pms.pojo.entity.TWhWarehouseCustomerMaterial;
import com.techsoul.module.pms.pojo.param.TWhWarehouseCustomerMaterialSaveParam;
import com.techsoul.module.pms.pojo.param.TWhWarehouseCustomerMaterialSearchParam;
import com.techsoul.module.pms.pojo.vo.TWhWarehouseCustomerMaterialVo;
import com.techsoul.module.pms.service.ITWhWarehouseCustomerMaterialService;
import com.techsoul.module.system.enmus.ErrorType;
import com.techsoul.module.system.pojo.entity.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 共享仓储客户物料 Controller
 *
 * @author liuen
 * @date 2022-12-30
 */
@Api(tags = "共享仓储客户物料")
@Slf4j
@RestController
@RequestMapping("/pms/tWhWarehouseCustomerMaterial")
public class TWhWarehouseCustomerMaterialController {

    @Autowired
    private Result result;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private ITWhWarehouseCustomerMaterialService service;

    @ApiOperation("新增")
    @Log(title = "共享仓储客户物料", operationType = OperationTypeEnum.INSERT)
    @PreAuthorize("hasAnyAuthority('pms:tWhWarehouseCustomerMaterial:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody TWhWarehouseCustomerMaterialSaveParam params) {
        return result.success(this.service.insert(params));
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @Log(title = "共享仓储客户物料", operationType = OperationTypeEnum.DELETE)
    @PreAuthorize("hasAnyAuthority('pms:tWhWarehouseCustomerMaterial:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @Log(title = "共享仓储客户物料", operationType = OperationTypeEnum.UPDATE)
    @PreAuthorize("hasAnyAuthority('pms:tWhWarehouseCustomerMaterial:update')")
    @PutMapping
    public Result update(@Valid @RequestBody TWhWarehouseCustomerMaterialSaveParam params) {
        return result.success(this.service.update(params));
    }

    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('pms:tWhWarehouseCustomerMaterial:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
   // @PreAuthorize("hasAnyAuthority('pms:tWhWarehouseCustomerMaterial:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody TWhWarehouseCustomerMaterialSearchParam params) {
        return result.success(this.service.findAll(params));
    }

    @ApiOperation("列表-分页")
  //  @PreAuthorize("hasAnyAuthority('pms:tWhWarehouseCustomerMaterial:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody TWhWarehouseCustomerMaterialSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, current, pageSize));
    }

    @ApiOperation("获取品牌")
    @PostMapping("/findVehicleBrand")
    public Result findVehicleBrand(@RequestBody TWhWarehouseCustomerMaterialSearchParam params) {
        return result.success(this.service.findVehicleBrand(params));
    }

    @ApiOperation("获取车型")
    @PostMapping("/findVehicleModel")
    public Result findVehicleModel(@RequestBody TWhWarehouseCustomerMaterialSearchParam params) {
        return result.success(this.service.findVehicleModel(params));
    }
}
